home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swags_z.zip / STRINGS.SWG / 0073_String Comparision.pas < prev    next >
Pascal/Delphi Source File  |  1994-02-03  |  2KB  |  45 lines

  1.  
  2. {*********************************************************************}
  3. PROGRAM StrCompare;             { Jan 23/94, Greg Estabrooks.         }
  4. USES CRT;                       { IMPORT Clrscr,WriteLn.              }
  5. VAR
  6.    SubName :STRING;             { Holds the Subject name entered.     }
  7.  
  8. FUNCTION StrCmp( Str1,Str2 :STRING ) :BOOLEAN;
  9.                             { Case InSensitive Routine to compare two }
  10.                             { strings.                                }
  11. VAR
  12.    StrPos   :BYTE;              { Current position within Strings.    }
  13.    CmpResult:BOOLEAN;           { Result of comparison.               }
  14. BEGIN
  15.   CmpResult := TRUE;            { Initialize 'CmpResult' to TRUE.     }
  16.   IF Length(Str1) <> Length(Str2) THEN { If not same length then don't}
  17.     CmpResult := FALSE                 { Bother converting case and   }
  18.                                        { compareing.                  }
  19.   ELSE
  20.     BEGIN
  21.       StrPos := 0;              { Initialize 'StrPos' to 0.           }
  22.       REPEAT                    { Loop until every char checked.      }
  23.         INC(StrPos);            { Point to next char.                 }
  24.         IF UpCase(Str1[StrPos]) <> UpCase(Str2[StrPos]) THEN
  25.          BEGIN
  26.            CmpResult := False;  { If there not the same then return   }
  27.                                 { a FALSE result.                     }
  28.            StrPos := Length(Str2); { Now set loop exit condition.     }
  29.          END;
  30.       UNTIL StrPos = Length(Str2);
  31.     END;
  32.   StrCmp := CmpResult;
  33. END;{StrCmp}
  34.  
  35. BEGIN
  36.   Clrscr;                       { Clear away the screen.              }
  37.   Write(' Name of subject ? :');{ Prompt user for subject name.       }
  38.   Readln(SubName);              { Now get users input.                }
  39.   IF StrCmp('English',SubName) THEN { If there the same then tell user}
  40.     Writeln('You chose ENGLISH')
  41.   ELSE                          { If not then ..............          }
  42.     Writeln('Unknown Subject!',^G);{Tell user its unknown.            }
  43. END.{StrCompare}
  44. {*********************************************************************}
  45.